package com.lb.base.util;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONReader;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ClassPathResource;

import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 类路径工具类
 *
 * @author xiemingzhi
 * @since 1.0
 */
@Slf4j
public class ClassPathUtils {

    /**
     * 根据类路径读取 JSON 对象
     * @param path 类路径
     * @return JSON 对象
     */
    public static JSONObject readJSONObject(String path) {
        try {
            return new JSONReader(new InputStreamReader(new ClassPathResource(path).getInputStream())).readObject(JSONObject.class);
        } catch (IOException e) {
            return new JSONObject();
        }
    }
}
